//
//  CZMainViewController.swift
//  WeiboDemo
//
//  Created by 秦川 on 16/5/9.
//  Copyright © 2016年 秦川. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //  添加子控制的两种方式
        //  viewControllers
        //  addChildViewController(<#T##childController: UIViewController##UIViewController#>)
        addChildViewController(CZHomeTableViewController(),title: "首页",imageName: "tabbar_home")
        
        addChildViewController(CZMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(CZDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(CZProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func addChildViewController(childController: UIViewController,title: String,imageName: String) {
       UITabBar.appearance().tintColor = UIColor.orangeColor()
        childController.tabBarItem.title = title
        childController.navigationItem.title = title
//        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        
//        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
